package com.souche.employment.mapper;

import com.souche.employment.domain.UserDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * userMapper.java created at 2017年8月9日 下午2:23:36
 *
 * @author Ray [email:rayinhangzhou@hotmail.com]
 * Revision History
 * Date            Programmer                   Notes
 * ----------------------------------------------------------
 **/
@Mapper
public interface UserMapper {

    @Select("select * from user where id = #{id}")
    UserDO getUser(String id);

    @Insert("insert into user (id, type, name, password, date_create) values(#{id}, #{type}, #{name}, #{password}, now())")
    void addUser(UserDO userDO);

    @Update("update user set name=#{name}, type=#{type}, password=#{password} where id=#{id}")
    void updateUser(UserDO userDO);

    @Update("update user set date_delete = unix_timestamp(now()) where id = ${id}")
    void deleteUser(String id);


    @Select("select * from user where id = #{mail} and type='hr' or type='manager'")
    UserDO getUserByLoginMail(String mail);

    @Select("select id, name, type from user where date_delete=0 order by id asc")
    List<UserDO> getForList();

    @SelectProvider(type = SqlProvider.class, method = "findUsers")
    @Results({
            @Result(property = "dateCreate", column = "date_create"),
            @Result(property = "dateUpdate", column = "date_update")
    })
    List<UserDO> search(@Param("id") String id, @Param("type") String type, @Param("sort") String sort);

}
